package com.zhuozhengsoft.pageoffice6springboot2back.controller;

import com.zhuozhengsoft.pageoffice.FileSaver;
import com.zhuozhengsoft.pageoffice.OpenModeType;
import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;
import com.zhuozhengsoft.pageoffice6springboot2back.util.GetDirPathUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping(value = "/SimplePPT")
public class SimplePPTController {
    //获取doc目录的磁盘路径
    private final String dir = GetDirPathUtil.getDirPath() + "static/doc/";

    public SimplePPTController() throws IOException {
    }

    @RequestMapping(value = "/PPT")
    public String showPPT(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.webOpen("/doc/SimplePPT/test.pptx", OpenModeType.pptNormalEdit, "张三");
        return poCtrl.getHtml();
    }

    @RequestMapping("save")
    public void save(HttpServletRequest request, HttpServletResponse response) {
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(dir + "SimplePPT/" + fs.getFileName());
        fs.close();
    }

}
